#!/usr/bin/python3

import psutil

r'''1.显示CPU相关的信息'''
def cpu_info():
    print ("查看CPU所有的信息")
    all_info = psutil.cpu_times()
    print (all_info)
    print ("显示cpu所有逻辑信息")
    logi = psutil.cpu_times(percpu=True)
    print (logi)
    print ("查看用户的cpu时间比")
    cpu_user_time = psutil.cpu_times().user
    print (cpu_user_time)
    print ("查看cpu逻辑个数")
    logi_num = psutil.cpu_count()
    print (logi_num)
    print ("查看cpu物理个数")
    phy_num = psutil.cpu_count(logical=False)
    print (phy_num)
    print ("查看CPU使用率")
    cpu_use = psutil.cpu_percent()
    print (cpu_use) 
    print ("查看每个CPU的使用率")
    cpu_per = psutil.cpu_percent(percpu=True)
    print (cpu_per)
    print ("查看CPU时间分配情况")
    cpu_time = psutil.cpu_times()
    print (cpu_time)



r'''2.显示与磁盘相关的信息 '''
def disk_info():
    print ("磁盘IO信息")
    disk_io = psutil.disk_io_counters()    
    print (disk_io)
    print ("获取磁盘的完整信息")
    disk_all = psutil.disk_partitions()
    print (disk_all)
    print ("获取分区表的参数")
    disk_part = psutil.disk_usage('/')
    print (disk_part)
    print ("获取硬盘IO总个数")
    disk_io_num = psutil.disk_io_counters()
    print (disk_io_num)
    print ("获取单个分区IO个数")
    disk_part_io = psutil.disk_io_counters(perdisk=True)
    print (disk_part_io)


r'''3.显示内存相关的信息'''
def memory_info():
    print ("系统内存的所有信息")
    mem = psutil.virtual_memory()
    print (mem)
    print ("系统总计内存")
    mem_total = mem.total
    print (mem_total)
    print ("系统已经使用内存")
    mem_use = mem.used
    print (mem_use)
    print ("系统空闲内存")
    mem_fre = mem.free
    print (mem_fre)
    print ("获取swap内存信息")
    swap = psutil.swap_memory()
    print (swap)


r'''4.显示网络相关的信息'''
def network_info():
    print ("获取网络总IO信息")
    net_all = psutil.net_io_counters()  
    print (net_all)
    print ("输出网络每个接口信息")
    net_int = psutil.net_io_counters(pernic=True)
    print (net_int)


r'''创建main函数调用以上函数'''
def main():
    print ('''\t1.显示CPU信息\n\t2.显示磁盘信息\n\t3.显示内存信息\n\t4.显示网络信息\n''')
    option = int(input("请输入操作选项:"))
    if option == 1:
        cpu_info()
    elif option == 2:
        disk_info()
    elif option == 3:
        memory_info()
    elif option == 4:
        network_info()
    else:
        print ("输入数字!")

main()
